package com.finger.gulimall.order.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

@Configuration
public class GulimallSessionConfig {

    /**
     *  session 上传到前端的配置
     * @return CookieSerializer
     */
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        // 指定session上传到前端cookie的key名字
        cookieSerializer.setCookieName("GULIJESESSION");
        // 设置cookie的作用范围
        cookieSerializer.setDomainName("gulimall.com");
        return cookieSerializer;
    }

    /**
     * 指定redis的序列化机制
     * @return RedisSerializer
     */
    @Bean
    public RedisSerializer redisSerializer(){
        return new GenericJackson2JsonRedisSerializer();
    }

}
